Page({
    data: {
        display: 'none',
        TEvent: '',
        addme: '添加本人',
        addMe: '',
        fileList: [],
        userUnionid: 0,
        isShow: false,
        isEventOne: true,
        isEventTwo: false,
        isEventThree: false,
        isEventFour: false,
        date: "",
        text: "",
        sub_num: 0,
        isShowEvent: true,
        isShowaDate: true,
        isShowMe: true
    },
    onLoad: function () {
        var date = new Date();
        //年  
        var Y = date.getFullYear();
        //月  
        var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
        //日  
        var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
        this.setData({
            date: Y+'-'+M+'-'+D
        });
    },
    onClickShow() {
        this.setData({
            isShow: true,
            isEventOne: true,
            isEventTwo: false,
            isEventThree: false,
            isEventFour: false
        })
    },
    onClickDate() {
        dd.datePicker({
            format: 'yyyy-MM-dd',
            currentDate: this.data.date,
            success: (res) => {
                this.setData({ date: res.date, isShowaDate: false });
            },
        });
    },
    onClickHide(e) {
        this.setData({ isShow: false, TEvent: e.target.dataset.hi, isShowEvent: false });
    },
    onClickEvent(e) {
        if (e.target.dataset.one == 'one') {
            this.setData({ isEventOne: false, isEventTwo: true, isEventThree: true, text: e.target.dataset.val + ',' });
        } else {
            this.setData({ isEventOne: false, isEventTwo: true, isEventFour: true, text: e.target.dataset.val + ',' });
        }

    },
    formSubmit: function (e) {
        // console.log('form发生了submit事件，携带数据为：', e.detail.value)
        let arr = e.detail.value;
        if (arr.eventName == '') {
            dd.alert({
                // title: '亲',
                content: '请选择事件',
                buttonText: '确定',
                success: () => {
                },
            });

            return false;
        }
        if (arr.userUnionid == 0) {
            dd.alert({
                // title: '亲',
                content: '请选择申请对象',
                buttonText: '确定',
                success: () => {
                },
            });
            return false;
        }
        if (arr.codeB == '') {
            dd.alert({
                // title: '亲',
                content: '请输入申请分数',
                buttonText: '确定',
                success: () => {
                },
            });
            return false;
        }
        if (arr.openC == true && arr.codeC == '') {
            dd.alert({
                // title: '亲',
                content: '请输入申请C分',
                buttonText: '确定',
                success: () => {
                },
            });
            return false;
        }
        if (arr.date == '') {
            dd.alert({
                // title: '亲',
                content: '请选择申请时间',
                buttonText: '确定',
                success: () => {
                },
            });
            return false;
        }

        var that = this;
        that.setData({ sub_num: that.data.sub_num + 1 });
        if (that.data.sub_num > 1) {
            dd.showToast({
                type: 'success',
                content: '请勿重复提交',
                duration: 3000,
                success: () => {
                }
            })
            return false;
        }
        dd.httpRequest({
            headers: {
                "Content-Type": "application/json"
            },
            url: 'http://smallroutine.changyuelife.com/eapp/saveApproval',
            method: 'POST',
            data: JSON.stringify(e.detail.value),
            dataType: 'json',
            success: function (res) {
                if (res.data.code == "0000") {
                    that.setData({ sub_num: 0 });
                    dd.showToast({
                        type: 'success',
                        content: '提交成功',
                        duration: 3000,
                        success: () => {
                        },
                    });
                    dd.reLaunch({
                        url: '/pages/index/index'
                    })
                } else {
                    dd.alert({ content: res });
                }

            },
        });
    },
    addOnly() {
        let that = this;
        dd.getStorage({
            key: 'userinfo',
            success: function (res) {
                let userInfo = res.data;
                that.setData({
                    addMe: userInfo.nick,
                    addme: '已添加本人',
                    userUnionid: userInfo.unionid,
                    isShowMe: false
                })
            },
        })
    }


})